package toanstt.gameplay;

import toanstt.com.T;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint.Align;

public class ManaView 
{
	int x;
	int y;
	int width;
	int height;
	Matrix mat;
	int dx;
	boolean ispause = false;
	float CURRENT_TIME;
	long start_system_time,d_system_time,current_system_time;
	int dem=0;
	public ManaView(int _x,int _y,int _width,int _height)
	{
		dem=0;
		x = _x;
		y = _y;
		width = _width;
		height = _height;
		mat = new Matrix();
		mat.postScale(width*1.0f/300, height*1.0f/50);
		mat.postTranslate(x, y);
		start_system_time =System.currentTimeMillis();
		CURRENT_TIME=0;
	}
	public void Draw(Canvas canvas)
	{
		T.paint.setColor(Color.BLUE);
		dx = (int)((T.PLAY_CURRENT_MANA*1.0f/T.PLAY_MANASIZE)*width);
		canvas.drawRect(x, y, x+dx, y+height, T.paint);
		canvas.drawBitmap(T.bitmap_manapool, mat, null);
		T.paint.setTextSize((int)(height/1.5));
		T.paint.setTextAlign(Align.CENTER);
		T.paint.setColor(Color.WHITE);
		canvas.drawText(T.PLAY_CURRENT_MANA +"/" + T.PLAY_MANASIZE, x+width/2,(int)( y+height/1.5),T.paint );
	}
	public void Update()
	{
		current_system_time = System.currentTimeMillis();
		d_system_time = (current_system_time-start_system_time);
		//if(CellTable.need_update_position==0)
		{
			CURRENT_TIME+=d_system_time/1000.0f;
			if(CURRENT_TIME>=1.5f)
			{
				CURRENT_TIME=CURRENT_TIME-1.5f;
				if(T.PLAY_CURRENT_MANA<T.PLAY_MANASIZE)
					T.PLAY_CURRENT_MANA++;
				dem++;
				if(dem%80 == 0)
					T.PLAY_UNLUCKY++;
			}
			
			//Log.d("aa", d_system_time+"");
		}
		start_system_time =current_system_time; 
	}
}
